package 笔试.网易;

import java.util.HashMap;

/**
 * @author:谢君臣
 * @Date:2021/8/21-16:34
 * @version:1.0
 * @function:
 */
public class Main02 {
    public static void main(String[] args) {
        System.out.println(findKthBit(1, 4));
    }
    public static char findKthBit (int n, int k) {
        // write code here
        StringBuilder string = createString(k);
        System.out.println(string.toString());
        return string.charAt(n);
    }
    public static StringBuilder createString(int k){
        if (k==1)
            return new StringBuilder("a");
        else {
            StringBuilder string = createString(k - 1);
            StringBuilder res = new StringBuilder();
            char temp = (char) ('a'+ (k-1));
            return new StringBuilder(res.append(string).append(temp).append((invert(string))));
        }
    }

    private static StringBuilder invert(StringBuilder string) {
        HashMap<Character,Character> hashMap = new HashMap<>();
        hashMap.put('a','z');
        hashMap.put('b','y');
        hashMap.put('c','x');
        hashMap.put('d','w');
        hashMap.put('e','v');
        hashMap.put('f','u');
        hashMap.put('g','t');
        hashMap.put('h','s');
        hashMap.put('i','r');
        hashMap.put('j','q');
        hashMap.put('k','p');
        hashMap.put('l','o');
        hashMap.put('m','n');
        hashMap.put('n','m');
        hashMap.put('o','l');
        hashMap.put('p','k');
        hashMap.put('q','j');
        hashMap.put('r','i');
        hashMap.put('s','h');
        hashMap.put('t','g');
        hashMap.put('u','f');
        hashMap.put('v','e');
        hashMap.put('w','d');
        hashMap.put('x','c');
        hashMap.put('y','b');
        hashMap.put('z','a');
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < string.length(); i++) {
            res.append(hashMap.get(string.charAt(i)));
        }
        return res.reverse();
    }
}
